/**
 * Created by Churcy on 2017/1/10.
 */
/**
 * Created by Churcy on 2017/1/9.
 */

window.onload = function() {
	Line.searchLine()
};

var Line = {

	searchLine : function() {
		$("#searchBTN").on('click', function() {
			var conditions = getCurrentConditions();
			conditions.pageNo = 1;
			ajaxSearchLineList(conditions);
		});
		$("#resetBTN").on('click', function() {
			resetFn();
		});
	}
}
function searchFn() {
	var conditions = getCurrentConditions();
	console.log("searchFN")
	var response = ajaxSearchLineList(conditions);
}
function resetFn() {
	$("#lineCode").val("");
	$("#lineName").val("");
}

function getCurrentConditions() {

	console.log("getCurrentConditions");

	var lineCode = $("#lineCode").val();
	var lineName = $("#lineName").val();
	var pageNo = $("#p").val();
	var APP_KEY = $('#APP_KEY').val();
	var conditions = {
		lineCode : lineCode,
		lineName : lineName,
		pageIndex : pageNo
	};
	return conditions;

}
function ajaxSearchLineList(conditions) {
	console.log("ajaxSearchLineList");
	$.ajax({
		type : "GET",
		url : PROJECT_CTX + "/trafficback/lineList",
		data : conditions,
		dataType : "json",
		success : function(data) {
			console.log(data)
			var result = eval(data);
			var resultCode = result.status.code;
			console.log(resultCode)
			console.log(result.line);
			if (1 == resultCode) {
				// 清空当前数据
				var lineList = $("#lineList").empty();
				// 填写查询出来的数据
				$.each(result.line, function(i, item) {
					var tr = "<tr>";

					tr += "<td >";
					tr += item.category;
					tr += "</td>"

					tr += "<td >";
					tr += item.circle;
					tr += "</td>"

					tr += "<td >";
					tr += item.companyName;
					tr += "</td>"

					tr += "<td >";
					tr += item.deptCode;
					tr += "</td>"

					tr += "<td >";
					tr += item.deptName;
					tr += "</td>"

					tr += "<td >";
					tr += item.gpsCode;
					tr += "</td>"

					tr += "<td >";
					tr += item.lineCode;
					tr += "</td>"

					tr += "<td >";
					tr += item.lineName;
					tr += "</td>"

					tr += "<td >";
					tr += item.lineShort;
					tr += "</td>"

					tr += "<td >";
					tr += item.lineCount;
					tr += "</td>"

					/*tr += "<td >";
					tr += " <a title='修改' href='#'>修改</a>";
					tr += " <a title='删除' href='#'>删除</a>";
					tr += "</td >";*/

					tr += "</tr>";
					lineList.append(tr);
					// 更新分页栏
					reloadPage(result);
				});
			}

		}
	});
}

